﻿////圆柱公式1
window.addEventListener("load", function () { btn1.disabled = true; })
let btn1 = document.querySelector("#yuanzhu1").querySelector("button");
let ipt1 = document.querySelector("#yuanzhu1").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt1[0].value == "" || ipt1[1].value == "" || ipt1[2].value == "" || ipt1[3].value == "" || ipt1[4].value == "")) {
        btn1.disabled = false;
    } else { btn1.disabled = true; }
    console.log(ipt1[5].value)
})
btn1.addEventListener("click", function () {
    let m = 3.14159 * parseFloat(ipt1[0].value) * parseFloat(ipt1[1].value)/1000 * (Math.pow((parseFloat(ipt1[3].value)/2000), 2) 
        - Math.pow((parseFloat(ipt1[2].value)/2000), 2))
    let jieGuo = (3.14159 / 32) * parseFloat(ipt1[0].value) * parseFloat(ipt1[1].value) / 1000 *
        (Math.pow(((parseFloat(ipt1[3].value)) / 1000), 4) - Math.pow(((parseFloat(ipt1[2].value)) / 1000), 4)) +
        (Math.pow(ipt1[4].value, 2))*m
    console.log(m)
    ipt1[5].value = jieGuo.toFixed(4);
    ipt1[6].value = jieGuo
})
/////圆柱公式2
window.addEventListener("load", function () { btn2.disabled = true; })
let btn2 = document.querySelector("#yuanzhu2").querySelector("button");
let ipt2 = document.querySelector("#yuanzhu2").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt2[0].value == "" || ipt2[1].value == "" || ipt2[2].value == "" || ipt2[3].value == "" || ipt2[4].value == "")) {
        btn2.disabled = false;
    } else { btn2.disabled = true; }
})
btn2.addEventListener("click", function () {
    let m = 3.14159 * parseFloat(ipt2[0].value) * parseFloat(ipt2[3].value) / 1000 * (Math.pow((parseFloat(ipt2[2].value) / 2000), 2)
        - Math.pow((parseFloat(ipt2[1].value) / 2000), 2))
    let jieGuo = 0.25 * m* ((Math.pow((parseFloat(ipt2[1].value))/1000, 2) + Math.pow((parseFloat(ipt2[2].value))/1000, 2))
        / 4 + (Math.pow((parseFloat(ipt2[3].value))/1000, 2) / 3)) + m * Math.pow(parseFloat(ipt2[4].value), 2)
    ipt2[5].value = jieGuo.toFixed(4);
    ipt2[6].value = jieGuo ;
})
/////方形物体
window.addEventListener("load", function () { btn3.disabled = true; })
let btn3 = document.querySelector("#fangxing").querySelector("button");
let ipt3 = document.querySelector("#fangxing").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt3[0].value == "" || ipt3[1].value == "" || ipt3[2].value == "" || ipt3[3].value == "")) {
        btn3.disabled = false;
    } else { btn3.disabled = true; }
})
btn3.addEventListener("click", function () {
    let m = parseFloat(ipt3[0].value) * parseFloat(ipt3[1].value) / 1000 * parseFloat(ipt3[2].value) / 1000 * parseFloat(ipt3[3].value) / 1000;
 
    let jieGuo = (1 / 12) *m *
                 (Math.pow((parseFloat(ipt3[1].value))/1000, 2) + Math.pow((parseFloat(ipt3[2].value))/1000, 2))
                 + m * Math.pow(parseFloat(ipt3[4].value), 2)
    ipt3[5].value = jieGuo.toFixed(4);
    ipt3[6].value = jieGuo;
})
////饼状物体
window.addEventListener("load", function () { btn4.disabled = true; })
let btn4 = document.querySelector("#bing").querySelector("button");
let ipt4 = document.querySelector("#bing").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt4[0].value == "" || ipt4[1].value == "" || ipt4[2].value == "")) {
        btn4.disabled = false;
    } else { btn4.disabled = true; }
})
btn4.addEventListener("click", function () {
    let m = 3.14159 * parseFloat(ipt4[0].value) * parseFloat(ipt4[2].value) / 1000 * (Math.pow((parseFloat(ipt4[1].value) / 2000), 2));
    console.log(m)
    let jieGuo = 0.125 * m * Math.pow((parseFloat(ipt4[1].value))/1000, 2) +
                m * Math.pow((parseFloat(ipt4[3].value))/1000, 2)
    ipt4[4].value = jieGuo.toFixed(4);
    ipt4[5].value = jieGuo;
})
////直线运动
window.addEventListener("load", function () { btn5.disabled = true; })
let btn5 = document.querySelector("#zhixian").querySelector("button");
let ipt5 = document.querySelector("#zhixian").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt5[0].value == "" || ipt5[1].value == "")) {
        btn5.disabled = false;
    } else { btn5.disabled = true; }
})
btn5.addEventListener("click", function () {
    let jieGuo = parseFloat(ipt5[0].value) * Math.pow((parseFloat(ipt5[1].value) / 6.28318), 2)
    ipt5[2].value = jieGuo.toFixed(4);
    ipt5[3].value = jieGuo;
})
////直接惯量计算
window.addEventListener("load", function () { btn6.disabled = true; })
let btn6 = document.querySelector("#zhijie").querySelector("button");
let ipt6 = document.querySelector("#zhijie").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(ipt6[0].value == "" || ipt6[3].value == "" || ipt6[4].value == "")) {
        btn6.disabled = false;
    } else { btn6.disabled = true; }
})
btn6.addEventListener("click", function () {
    if (ipt6[1].checked) {
        ///选中实心
        let jieguo = (2 / 5) * parseFloat(ipt6[0].value) * Math.pow((parseFloat(ipt6[3].value))/1000, 2) + parseFloat(ipt6[0].value) * Math.pow((parseFloat(ipt6[4].value))/1000, 2)
        ipt6[5].value = jieguo;
        ipt6[6].value = jieguo
    } else {
        ///选中薄壁
        let jieguo = (2 / 3) * parseFloat(ipt6[0].value) * Math.pow((parseFloat(ipt6[3].value))/1000, 2) + parseFloat(ipt6[0].value) * Math.pow((parseFloat(ipt6[4].value))/1000, 2)
        ipt6[5].value = jieguo.toFixed(4);
        ipt6[6].value = jieguo
    }
})